import Vue from "vue";
import Vant from "vant";
import "vant/lib/index.css";
import App from "./App.vue";
import router from "./router";
import axios from "axios";
import store from "./store";
import "./http";
import "babel-polyfill";
import wx from "weixin-js-sdk";
import VueAwesomeSwiper from "vue-awesome-swiper";
// require styles
import "swiper/dist/css/swiper.css";
import "aplayer/dist/APlayer.min.css";
import "./assets/index.css";
import VueCookies from "vue-cookies";
Vue.use(VueAwesomeSwiper /* { default global options } */);
Vue.use(Vant);
Vue.use(VueCookies);
Vue.config.productionTip = false;
Vue.prototype.$http = axios;
Vue.prototype.$wx = wx;
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount("#app");
router.beforeEach(async (to, from, next) => {
  debugger
  console.log("==to, from",to, from)
  // let res = await axios.get(`api/index/share_page`);
  // console.log(res);
  // console.log(location.href);
  // console.log(process);
  if (!VueCookies.get("token") && location.href.split("token=")[1]) {
    let query = location.href.split("?")[1];
    let queryarr = query.split("#")[0];
    VueCookies.set(`token`, queryarr.split("=")[1]);
  }
  if (!VueCookies.get("token")) {
    location.href = `${process.env.VUE_APP_BACKURL}/third/connect/wechat?url=${
      location.href.split("?")[0]
    }`;
  } else {
    next();
  }
});



